#include "stdafx.h"
#include "CMSGKeyboardCon.h"
#include "MainMenuPainter.h"
#include "IResCfg.h"
#include "CMSGInforCon.h"
#include "MainPro.h"
CMSGKeyboardCon::CMSGKeyboardCon(HWND hWnd):CMSGInforCon(hWnd)
{
	m_strShow=L"";
}

CMSGKeyboardCon::~CMSGKeyboardCon(void)
{
}

BOOL CMSGKeyboardCon::InitControls(DWORD dwData)
{
	//message box
	LANGUAGE_DECLARE;
	FONT_DECLARE;

	HBITMAP hBitmap = NULL;

	CIResCfg ResCon;
	if(!ResCon.Init(L"MSGKeyBoard.xml"))
	{
		//g_App.ShowMsgBox(CMD_MSGBOX_OK,L"",LAN_GETTEXT(Msg_ResError));
		return FALSE;
	}

	m_nAniType  = ResCon.GetAniType();
	m_nExitAniType=ResCon.GetExitAniType();
	m_nAniSpeed = ResCon.GetAniSpeed();
	SetRect(ResCon.GetRect());
	BOOL bFromDll = ResCon.IsResFromDll();
	BtnParam btnInfo;

	hBitmap = CUtil::LoadBitmapEx(ResCon.GetImage(),bFromDll);
   	this->SetMaskBmp(hBitmap);

	BatTimePicParam picInfo;
	ResCon.GetBatTimePicParam(picInfo,L"Pic_Bkgnd");
	CPicture *pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC, L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);

	TextParam txtInfo;
	CText* pText=NULL; 


	//{
	ResCon.GetTextParam(txtInfo,L"Title");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(MSG_HS_PASSCODE_TITLE),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
	//}


	ResCon.GetTextParam(txtInfo,L"Password_Text");
	m_pText = (CText*)AddControl(new CText(SWS_STATIC,L"",txtInfo.m_rc, CMD_MSG_PASSWORD_TEXT));
	ResCon.SetTextParam(m_pText,txtInfo);



	CBmpBtn* pBtn = NULL;

	ResCon.GetBtnParam(btnInfo,L"Btn_No");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,LAN_GETTEXT(TXT_CANCLE),btnInfo.m_rc, CMD_MSG_FITSTREAM_CANCLE));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"Btn_yes");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_OK));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"Btn_0");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM0));
	ResCon.SetBtnParam(pBtn,btnInfo);
	

	ResCon.GetBtnParam(btnInfo,L"Btn_1");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM1));
	ResCon.SetBtnParam(pBtn,btnInfo);


	ResCon.GetBtnParam(btnInfo,L"Btn_2");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM2));
	ResCon.SetBtnParam(pBtn,btnInfo);


	ResCon.GetBtnParam(btnInfo,L"Btn_3");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM3));
	ResCon.SetBtnParam(pBtn,btnInfo);


	ResCon.GetBtnParam(btnInfo,L"Btn_4");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM4));
	ResCon.SetBtnParam(pBtn,btnInfo);


	ResCon.GetBtnParam(btnInfo,L"Btn_5");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM5));
	ResCon.SetBtnParam(pBtn,btnInfo);


	ResCon.GetBtnParam(btnInfo,L"Btn_6");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM6));
	ResCon.SetBtnParam(pBtn,btnInfo);


	ResCon.GetBtnParam(btnInfo,L"Btn_7");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM7));
	ResCon.SetBtnParam(pBtn,btnInfo);


	ResCon.GetBtnParam(btnInfo,L"Btn_8");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM8));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"Btn_9");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_NUM9));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"Btn_Clear");
	pBtn = (CBmpBtn*)AddControl(new CBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_PASSWORD_CLEAR));
	ResCon.SetBtnParam(pBtn,btnInfo);







	SetPainter(new CMainMenuPainter());
	return true;
}

void  CMSGKeyboardCon::OnCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
	switch (wParam)
	{
	case CMD_MSG_PASSWORD_NUM0:
		{
			m_num=m_num+L"0";
			m_strShow=m_strShow+L"*";
		    m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_NUM1:
		{
			m_num=m_num+L"1";
			m_strShow=m_strShow+L"*";
			m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_NUM2:
		{
			m_num=m_num+L"2";
			m_strShow=m_strShow+L"*";
			m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_NUM3:
		{
			m_num=m_num+L"3";
			m_strShow=m_strShow+L"*";
			m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_NUM4:
		{
			m_num=m_num+L"4";
			m_strShow=m_strShow+L"*";
			m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_NUM5:
		{
			m_num=m_num+L"5";
			m_strShow=m_strShow+L"*";
			m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_NUM6:
		{
			m_num=m_num+L"6";
			m_strShow=m_strShow+L"*";
			m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_NUM7:
		{
			m_num=m_num+L"7";
			m_strShow=m_strShow+L"*";
			m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_NUM8:
		{
			m_num=m_num+L"8";
			m_strShow=m_strShow+L"*";
			m_pText->SetCaption(m_strShow);
		}
	case CMD_MSG_PASSWORD_NUM9:
		{
			m_num=m_num+L"9";
			m_strShow=m_strShow+L"*";
			m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_CLEAR:
		{
			m_num=L"";
			m_strShow=L"";
			m_pText->SetCaption(m_strShow);
		}
		break;
	case CMD_MSG_PASSWORD_OK:
		{

			if (m_num==L"1609")
			{
               PostMessage(m_hWnd,WM_COMMAND, CMD_MSG_FITSTREAM_CANCLE,NULL);
			   Sleep(200);
			   PostMessage(m_hWnd,WM_CLICK_LONG, CMD_MAINNEU_SHOWCLUBSETTING,NULL);

			}
			if (m_num==L"2610")
			{
				PostMessage(m_hWnd,WM_COMMAND, CMD_MSG_FITSTREAM_CANCLE,NULL);
				Sleep(200);
			


				STARTUPINFO si;
				PROCESS_INFORMATION info;

				ZeroMemory( &si, sizeof(si) );
				si.cb = sizeof(si);
				ZeroMemory( &info, sizeof(info) );

			
				if (CreateProcess(_T("\\Windows\\ctlpnl.exe"), _T("cplmain.cpl,13,0"), NULL, NULL, NULL, 
					0, NULL, NULL,&si,&info))
				{
					g_App.m_bNeedScreen=false;
					//SetCursor( NULL );
					ShowCursor(SW_HIDE);
					KillTimer(m_hWnd,FONT_ALPHA);
					KillTimer(m_hWnd,START_INTERVAL);
					KillTimer(m_hWnd,SCREEN_PROTECTED);
					CloseHandle(info.hThread);
					CloseHandle(info.hProcess);
				}	

				//PostMessage(m_hWnd,WM_CLICK_LONG, CMD_MAINNEU_CLUBSETTING,NULL);

			}
			else
			{
				m_num=L"";
				m_strShow=L"";
				m_pText->SetCaption(m_strShow);
			}
			break;
		}
	default:
		break;
	}

	InvalidateRect(m_hWnd,m_pText->GetRect(),FALSE);
}